#include "stdafx.h"
#include "TimerClass.h"


CTimerClass::CTimerClass(void) : m_nFrequency(0), m_nStartTime(0), m_fTickPerMS(0.0f), m_fFrameTime(0.0f)
{
}


CTimerClass::~CTimerClass(void)
{
}

bool CTimerClass::Initialize()
{
	QueryPerformanceFrequency((LARGE_INTEGER*)&m_nFrequency);
	if(m_nFrequency == 0)
	{
		DEBUG_OUTPUT("Time frequency returned zero");
		return false;
	}

	m_fTickPerMS = (float)(m_nFrequency / 1000);

	QueryPerformanceCounter((LARGE_INTEGER*)&m_nStartTime);

	return true;
}

void CTimerClass::Frame()
{
	INT64 nCurrentTime;
	float fTimeDifference;
	
	QueryPerformanceCounter((LARGE_INTEGER*)&nCurrentTime);
	fTimeDifference = (float)(nCurrentTime - m_nStartTime);
	m_fFrameTime = fTimeDifference / m_fTickPerMS;
	m_nStartTime = nCurrentTime;
}

float CTimerClass::GetTime()
{
	return m_fFrameTime;
}